package com.r2coding.music.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import com.r2coding.common.enums.Module;
import com.r2coding.common.enums.OperationType;
import com.r2coding.music.annotation.SysLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import com.r2coding.music.entity.SongListEntity;
import com.r2coding.music.service.SongListService;
import com.r2coding.common.util.PageUtils;
import com.r2coding.common.util.Result;

/**
 * 歌单
 *
 * @author 98k灬
 * @email hk666zx@163.com
 * @date 2022-05-04 20:46:11
 */
@RestController
@RequestMapping("/songList")
public class SongListController {
    @Autowired
    private SongListService songListService;

    /**
     * 保存
     */
    @SysLog(module = Module.MUSIC, operationType = OperationType.INSERT, description = "保存歌单")
    @PreAuthorize("hasAuthority('songList:add')")
    @PostMapping("/saveSongList")
    public Result save(@RequestBody SongListEntity songListEntity){
        songListEntity.setDeleted(0);
        songListEntity.setUpdateTime(new Date());
        songListEntity.setCreateTime(new Date());
        songListService.save(songListEntity);
        return Result.ok();
    }

    /**
     * 修改
     */
    @SysLog(module = Module.MUSIC, operationType = OperationType.UPDATE, description = "修改歌单")
    @PreAuthorize("hasAuthority('songList:edit')")
    @PostMapping("/update")
    public Result update(@RequestBody SongListEntity songListEntity){
        songListEntity.setUpdateTime(new Date());
        songListService.updateById(songListEntity);
        return Result.ok();
    }

    /**
     * 删除
     */
    @SysLog(module = Module.MUSIC, operationType = OperationType.DELETE, description = "删除歌单")
    @PreAuthorize("hasAuthority('songList:delete')")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Integer id){
        songListService.delete(id);
        return Result.ok();
    }

}
